﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using LybrixNursingCommon;
using LybrixNursingCRMDesktop.FrameWork;
using System.ComponentModel;

namespace LybrixNursingCRMDesktop
{
    /// <summary>
    /// Interaction logic for Sapakem.xaml
    /// </summary>
    /// 

    public class item
    {
        string id;
        string name;


        public item() {}
        public item(string _name, string _id)
        {
            id = _id;
            name = _name;
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        public string Id
        {
            get { return id; }
            set { id = value; }
        }
    }
    public partial class Sapakem : Page
    {
        private NursingDBContainer _entities;
        private Sapak currentSapak = null;
        public Sapakem()
        {
            InitializeComponent();
            _entities = Repository.Entities;
            InitializeComboBox();
            PerformSearch();
        }

        private void InitializeComboBox()
        {
            List<item> names = new List<item> {new item( "ריק" ,"1"), new item("פרטי" , "2"), new item("חברה" ,"3")};
           
            sapakType.SetItemsSource = null;
            sapakType.SetItemsSource = names;
            
        
        }


        private void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            PerformSearch();
        }


        public void PerformSearch()
        {
            IQueryable<Sapak> sapakem = null;
            sapakem = (from x in _entities.Sapaks select x);
            if (sapakID.GotValue)
                sapakem = sapakem.Where(DynamicExpressions.GetWhereCond<Sapak>(sapakID.FieldID, "Contains", sapakID.Value));





            SapakemListView.ItemsSource = sapakem;
        }

        private void ClearButton_Click(object sender, RoutedEventArgs e)
        {
            sapaktFName.Value = string.Empty;
            sapakID.Value = string.Empty;
            //saoakId.Value = string.Empty;
        }

        private void GridViewColumnHeaderClickedHandler(object sender, RoutedEventArgs e)
        {

        }

        private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {

            var dep = (DependencyObject)e.OriginalSource;
            while ((dep != null) && !(dep is ListViewItem))
            {
                dep = VisualTreeHelper.GetParent(dep);
            }
            if (dep == null)
                return;
            currentSapak = (Sapak)SapakemListView.ItemContainerGenerator.ItemFromContainer(dep);

        }

        private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
        {
            NavigationCenter.ShowDetailPage(currentSapak, NavigationTarget.SapakDetailsPage, this);
            e.Handled = true;
        }

    }
}
